<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>getQueryStringArgs</title>
</head>

<body>
    <p>打开浏览器控制台查看结果</p>
    <script>
        if (location.search.length <= 0) {
            location.search += 'q=javascript&num=10'
        }
        const getQueryStringArgs = () => {
            const qs = location.search.length > 0 ? location.search.substring(1) : '',
                args = {};
            const iterRes = qs.split('&').map(kv => kv.split('='));
            for (const item of iterRes) {
                const [name, value] = [decodeURIComponent(item[0]), decodeURIComponent(item[1])];
                if (name && name.length) {
                    args[name] = value;
                }
            }
            return args;
        }
        let args = getQueryStringArgs();
        console.log(args['q']); // "javascript"
        console.log(args['num']); // "10"
    </script>
</body>

</html>